package com.rerun.phone.memberuser;

import com.rerun.common.anno.ResponseExceptionReturn;
import com.rerun.common.bean.Rest;
import com.rerun.common.controller.SuperController;
import com.rerun.service.ISmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * The type Captcha controller.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /11/1 11:35
 */
@Api(value = "求职端-短信相关", description = "求职端-短信相关")
@RestController
@RequestMapping("/memberApi/sms")
public class SmsController extends SuperController {
    @Resource
    private ISmsService iSmsService;

    /**
     * 发送手机验证码.
     *
     * @param phoneNumber the phone number
     * @return the rest
     */
    @ApiOperation(value = "发送手机验证码", httpMethod = "POST", response = Rest.class, notes = "发送手机验证码")
    @RequestMapping(value = "/sendCaptcha/{phoneNumber}", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest send(@PathVariable("phoneNumber") String phoneNumber) {
        boolean flag = iSmsService.sendCaptcha(phoneNumber);
        return flag ? Rest.ok("发送成功") : Rest.failure("发送失败");
    }

    /**
     * 验证手机验证码.
     *
     * @param phoneNumber the phone number
     * @param code        the code
     * @return the rest
     */
    @ApiOperation(value = "验证手机验证码", httpMethod = "POST", response = Rest.class, notes = "验证手机验证码    200： 校验成功 验证成功后立即失效 如果不验证 5分钟后自动失效  500：校验失败  ")
    @RequestMapping(value = "/verifyCaptcha/{phoneNumber}/{code}", method = RequestMethod.POST)
    @ResponseExceptionReturn
    public Rest verify(@PathVariable("phoneNumber") String phoneNumber, @PathVariable("code") String code) {
        boolean flag = iSmsService.verifySmsCode(phoneNumber, code);
        return flag ? Rest.ok("校验成功") : Rest.failure("校验失败");
    }
}
